﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using zlib;

namespace Test
{
   static class DecodeKRC
    {
        private static char[] h = { '@', 'G', 'a', 'w', '^', '2', 't', 'G', 'Q', '6', '1', '-', 'Î', 'Ò', 'n', 'i' };
        static Byte[] databuffer = new Byte[1024];
       public static string Decode(string s)
        {
           
            int len = 0;
            FileStream rfs = new FileStream(@"C:\1.krc", FileMode.Open);
            FileStream wfs = new FileStream(@"C:\1.txt", FileMode.CreateNew);
            ZOutputStream zwfs = new ZOutputStream(wfs);

            //去掉头部4字节：
            rfs.Read(databuffer, 0, 4);

            while ((len = rfs.Read(databuffer, 0, 1024)) > 0)
            {
                for (int k = 0; k < len; k++)
                {
                    int m = k % 16;
                    databuffer[k] = (byte)(databuffer[k] ^ h[m]);//异或解密
                }

                zwfs.Read(databuffer, 0, len);//zlib解压缩
            }
          
            rfs.Close();
            zwfs.Close();
            return "";
        }
    }
}
